package xjtu.se.articlecommunity.user.home.dao;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import xjtu.se.articlecommunity.user.home.dto.ArtTabDto;
import xjtu.se.articlecommunity.user.home.dto.QueueFeedDto;
import xjtu.se.articlecommunity.user.home.dto.FeedDto;
import xjtu.se.articlecommunity.user.home.dto.SearchDto;

import java.util.List;

public interface UMainviewDao {
    @Select("select * from t_article_tab;")
    List<ArtTabDto> getTabList();

    @Select("select f.a_order,f.a_id,a_title,at_name,a_html,a_date,u.u_id,u_name,u_avatar,\n" +
            "(select ifchecked from t_article_like where t_article_like.a_id=a.a_id and t_article_like.u_id=#{u_id}) as iflike,"+
            "(select ifchecked from t_article_like where t_article_like.a_id=a.a_id and t_article_like.u_id=#{u_id}) as ifsub,"+
            "(select count(1) from t_subscription where t_subscription.a_id=f.a_id) as sub_count,\n" +
            "(select count(1) from t_comment where t_comment.a_id=f.a_id) as com_count,\n" +
            "(select count(1) from t_article_like where t_article_like.a_id=f.a_id and ifchecked=1) as like_count\n" +
            "from t_user u,t_feed f,t_article a,art_tab ,t_article_tab tab where u.u_id=a.u_id and f.a_id=a.a_id and " +
            "art_tab.a_id=a.a_id and art_tab.at_tab=tab.at_tab and f.at_tab=tab.at_tab and f.at_tab=#{at_tab} and a_status=1 order by f.a_order;")
    List<QueueFeedDto> getFeedList(@Param("at_tab") String at_tab, @Param("u_id") String u_id);

    @Select("select a.a_id,a.a_title,a.a_html,a_date,u.u_id,u.u_name,u.u_avatar,\n" +
            "(select count(1) from t_subscription where t_subscription.a_id=a.a_id) as sub_count,\n" +
            "(select count(1) from t_comment where t_comment.a_id=a.a_id) as com_count,\n" +
            "(select count(1) from t_article_like where t_article_like.a_id=a.a_id) as like_count \n" +
            "from t_user u,t_article a,t_follow f \n" +
            "where f.befollowed_u_id=a.u_id and f.befollowed_u_id=u.u_id and f.u_id=#{userid} and a_status=1 order by a.a_date DESC;")
    List<FeedDto> getFollowFeed(@Param("userid") String u_id);

    @Select("select a.a_id,a.a_title,a.a_html,a.a_date,u.u_id,u.u_name,u.u_avatar,\n" +
            "(select count(1) from t_subscription where t_subscription.a_id=a.a_id) as sub_count,\n" +
            "(select count(1) from t_comment where t_comment.a_id=a.a_id) as com_count,\n" +
            "(select count(1) from t_article_like where t_article_like.a_id=a.a_id) as like_count \n" +
            "from t_user u,t_article a \n" +
            "where a.u_id=u.u_id and a.a_date>#{time} and a_status=1 order by ${orderType} DESC;")
    List<FeedDto> getHotFeed(@Param("time") String time, @Param("orderType") String ordertype);

    List<FeedDto> getsearchArtList(SearchDto dto);
}
